/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ec.socialfun.convertidores;

import com.ec.socialfun.entidades.Zona;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author hp
 */

@FacesConverter("zonaConvertidor")
public class ZonaConvertidor implements Converter{

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String valor) {
        try{
            return new Zona(Integer.parseInt(valor));
        }catch(NumberFormatException e){
            return null;
        }
        
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object ooj) {
        try{
           Zona zona = (Zona)ooj;
           if(zona==null)
                return null;
           return zona.getZoCodigo().toString();
        }catch(Exception e){
            throw new UnsupportedOperationException("ZonaConvertidor .- Error al convertir a String ");
        }
    }
    
}
